// pages/afterSaleCente/afterSaleCente.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderProdcut:null,
    orderProductId:0,
    buyprice:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      orderProductId: options.orderProductId,
      orderid: options.orderid,
      status: options.status,
      orderStatus: options.status,
      refundprice: options.refundprice,
      refund: options.refund,
      exchange: options.exchange,
    });
    that.data.buyprice = options.buyprice
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight,
      
    })
   
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.globalData.url + 'goAfterSaleCente',
      method: 'GET',
      data: {
        orderProductId: that.data.orderProductId,
      },
      success: function (res) {
        that.setData({
          orderProdcut: res.data.data,
          exchange1: res.data.data.exchange,
          refund1: res.data.data.refund,
          refundPrice1: res.data.data.refundPrice,
        });
      },
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  refund: function (e) {
    var that = this;
    if (that.data.orderStatus == 7001){
      wx.navigateTo({
        url: '/pages/refundToFillOut/refundToFillOut?type=' + e.currentTarget.dataset.type + '&orderProductId=' + this.data.orderProductId + '&productId=' + this.data.orderProdcut.productId + '&orderid=' + this.data.orderid
      })
    } else {
      if (e.currentTarget.dataset.type == 1) {
        if (that.data.refund1 === true) {
          wx.navigateTo({
            url: '/pages/refundToFillOut/refundToFillOut?type=' + e.currentTarget.dataset.type + '&orderProductId=' + this.data.orderProductId + '&productId=' + this.data.orderProdcut.productId + '&orderid=' + this.data.orderid + '&buyprice=' + that.data.buyprice
          })
        } else {
          wx.showToast({
            title: "已过售后期",
            icon: 'none'
          })
        }
      } else{
        console.info(that.data.refundPrice1);
        if (that.data.refundPrice1 == true) {
          wx.navigateTo({
            url: '/pages/refundToFillOut/refundToFillOut?type=' + e.currentTarget.dataset.type + '&orderProductId=' + this.data.orderProductId + '&productId=' + this.data.orderProdcut.productId + '&orderid=' + this.data.orderid + '&buyprice=' + that.data.buyprice
          })
        } else {
          wx.showToast({
            title: "已过售后期",
            icon: 'none'
          })
        }
       
      }
      
      // if (e.currentTarget.dataset.type == 2) {
      //   if (that.data.exchange1 == true) {
      //     wx.navigateTo({
      //       url: '/pages/refundToFillOut/refundToFillOut?type=' + e.currentTarget.dataset.type + '&orderProductId=' + this.data.orderProductId + '&productId=' + this.data.orderProdcut.productId + '&orderid=' + this.data.orderid
      //     })
      //   } else {
      //     wx.showToast({
      //       title: "已过售后期",
      //       icon: 'none'
      //     })
      //   }
        
      // } else {
        
      // }
    }
    
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  navBack: function () {
    wx.navigateBack({

    })
  },
  //获取几天后的日期
  getDateStr: function (today, addDayCount) {
    console.info(addDayCount);
    var dd;
    if (today) {
      dd = new Date(today);
    } else {
      dd = new Date();
    }
    dd.setDate(parseInt(dd.getDate()) + parseInt(addDayCount));//获取AddDayCount天后的日期 
    var y = dd.getFullYear();
    var month = dd.getMonth() + 1;//获取当前月份的日期 
    var d = dd.getDate();
    var h = dd.getHours();
    var m = dd.getMinutes();
    var s = dd.getSeconds();
    if (m < 10) {
      m = '0' + m;
    };
    if (d < 10) {
      d = '0' + d;
    };
    return y + "-" + month + "-" + d + " " + h + ':' + m + ':' + s;
  },
})